home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / music_utilities / pt030.dms / pt030.adf / Less / Src / ttyin.c < prev    next >
C/C++ Source or Header  |  1987-06-15  |  902b  |  59 lines

  1. /*
  2.  * Routines dealing with getting input from the keyboard (i.e. from the user).
  3.  */
  4.  
  5. #include "less.h"
  6.  
  7. /*
  8.  * The boolean "reading" is set true or false according to whether
  9.  * we are currently reading from the keyboard.
  10.  * This information is used by the signal handling stuff in signal.c.
  11.  * {{ There are probably some race conditions here
  12.  *    involving the variable "reading". }}
  13.  */
  14. public int reading;
  15.  
  16. #ifdef AMIGA
  17. extern struct FileHandle *tty;
  18. #else
  19. static int tty;
  20. #endif
  21.  
  22.  
  23. /*
  24.  * Open keyboard for input.
  25.  * (Just use file descriptor 2.)
  26.  */
  27.     public void
  28. open_getchr()
  29. {
  30. #ifdef AMIGA
  31.     ttopen();
  32. #else
  33.     tty = 2;
  34. #endif
  35. }
  36.  
  37. /*
  38.  * Get a character from the keyboard.
  39.  */
  40.     public int
  41. getchr()
  42. {
  43.     char c;
  44.     int result;
  45.  
  46.     reading = 1;
  47.     do
  48.     {
  49.         flush();
  50. #ifdef AMIGA
  51.         result = Read(tty, &c, 1L);
  52. #else
  53.         result = read(tty, &c, 1);
  54. #endif
  55.     } while (result != 1);
  56.     reading = 0;
  57.     return (c & 0177);
  58. }
  59.